LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.all;
USE IEEE.STD_LOGIC_UNSIGNED.all;
USE WORK.filter;

--TESTBENCH DO FILTER

ENTITY tb_filter_2 IS
END tb_filter_2;

ARCHITECTURE logic OF tb_filter_2 IS

COMPONENT filter
    PORT(test_state: IN STD_LOGIC_VECTOR(4 DOWNTO 0) := "00000";
	     filter_enable: IN STD_LOGIC := '0';
        f_in: INOUT STD_LOGIC_VECTOR(13 DOWNTO 1);
	     f_out: INOUT STD_LOGIC_VECTOR(13 DOWNTO 1));
END COMPONENT;

SIGNAL test_state_in: STD_LOGIC_VECTOR(4 DOWNTO 0);
SIGNAL s_filter_enable: STD_LOGIC;
SIGNAL s_in: STD_LOGIC_VECTOR(13 DOWNTO 1);
SIGNAL s_out: STD_LOGIC_VECTOR(13 DOWNTO 1);

BEGIN
    tb_filter: filter
    PORT MAP(test_state=>test_state_in, filter_enable=>s_filter_enable, f_in=>s_in, f_out=>s_out);
    PROCESS
        TYPE pattern_record IS RECORD
            vi_test_state: STD_LOGIC_VECTOR(4 DOWNTO 0);
            vi_filter_enable: STD_LOGIC;
            vio_in: STD_LOGIC_VECTOR(13 DOWNTO 1);
				vio_out: STD_LOGIC_VECTOR(13 DOWNTO 1);
        END RECORD;
        TYPE pattern_tests IS ARRAY (NATURAL RANGE <>) OF pattern_record;
            CONSTANT patterns : pattern_tests :=
            (
                ("00000",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("00001",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("00001",'1',"1111111111111","ZZZZZZXZZZZZ1"),
                ("00010",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("00010",'1',"1111111111111","ZZZZZZXZZZZ11"),
                ("00011",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("00011",'1',"1111111111111","ZZZZZZXZZZZZZ"),--estado desconhecido
                ("10001",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("10001",'1',"1111111111111","11Z11ZXZ11Z11"),
                ("10010",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("10010",'1',"1111111111111","1Z1Z1ZXZ1Z1Z1"),
                ("10011",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("10011",'1',"1111111111111","1Z111ZXZ11111"),
                ("10100",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("10100",'1',"1111111111111","11Z11ZXZ11Z11"),
                ("10101",'0',"1111111111111","ZZZZZZXZZZZZZ"),
                ("10101",'1',"1111111111111","ZZZZZZXZZZZZZ") --estado desconhecido
            );
    BEGIN
        FOR i IN patterns'RANGE LOOP
				test_state_in <=  patterns(i).vi_test_state;
            s_filter_enable <= patterns(i).vi_filter_enable;
				s_in <= patterns(i).vio_in;
            WAIT FOR 100 ps;
				ASSERT s_out = patterns(i).vio_out REPORT "VALOR DE SAIDA IN ERRADO" SEVERITY error;
        END LOOP;
        ASSERT false REPORT "END." SEVERITY note;
        WAIT;
    END PROCESS;
END logic;
